<?php
class Msite extends CI_Model{
	function __construct(){
		parent::__construct();
	}
	function getSite(){
		$sql = "select * from tbsite where id = 1";
		$arr = array();
		$query = $this->db->query($sql);
		foreach ($query->result() as $row){
			$arr["id"] = $row->id;
			$arr["name"] = $row->name;
			$arr["title"] = $row->title;
			$arr["keywords"] = $row->keywords;
			$arr["sitedesc"] = $row->sitedesc;
			$arr["headlogo"] = $row->headlogo;
			$arr["headlogourl"] = $row->headlogourl;
			$arr["bottomlogo"] = $row->bottomlogo;
			$arr["bottomlogourl"] = $row->bottomlogourl;
			$arr["beian"] = $row->beian;
			$arr["stacode"] = $row->stacode;
			$arr["status"] = $row->status;
			$arr["bottominfo"] = $row->bottominfo;
			$arr["reginfo"] = $row->reginfo;
			$arr["anticheatguide"] = $row->anticheatguide;			
		}
		return $arr;
	}
	function setSite($name,$title,$keywords,$sitedesc,$headlogo,$bottomlogo,
							$beian,$stacode,$status,$bottominfo,$reginfo,$anticheatguide){
		//初始化
		$this->initSite();
		
		$sql = "update tbsite set name = ?,title = ?,keywords = ?,sitedesc = ?,headlogo = ?,bottomlogo= ?,
							beian = ?,stacode = ?,status = ?,bottominfo = ?,reginfo = ?,anticheatguide = ?
				where id = 1";
		$this->db->query($sql,array("$name","$title","$keywords","$sitedesc","$headlogo","$bottomlogo",
									"$beian","$stacode","$status","$bottominfo","$reginfo","$anticheatguide"));
		
		
	}
	function setHeadLogoUrl($headlogourl){
		$this->initSite();
		$sql = "update tbsite set headlogourl = ? where id = 1";
		$this->db->query($sql,array("$headlogourl"));
	}
	function setBottomLogoUrl($bottomLogoUrl){
		$this->initSite();
		$sql = "update tbsite set bottomlogourl = ? where id = 1";
		$this->db->query($sql,array("$bottomLogoUrl"));
	}
	function initSite(){
		$sql = "select * from tbsite where id = 1";
		$query = $this->db->query($sql);
		$exists = false;
		foreach ($query->result() as $row){
			$exists = true;
		}
		if($exists == false){
			$sql = "insert into tbsite(id) values(1)";
			$this->db->query($sql);
		}
	}
}
?>